package com.meituan.service;

import com.meituan.bo.UserBo;
import com.meituan.domain.Sex;
import com.meituan.domain.User;
import com.meituan.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService{

    @Resource
    private UserMapper userMapper;

    
    public void addUser(UserBo userBo){
        User user = new User();
        user.fromUserBo(userBo);
        userMapper.insert(user);
    }

    public int insertSelective(User pojo){
        return userMapper.insertSelective(pojo);
    }

    public int insertList(List<User> pojos){
        return userMapper.insertList(pojos);
    }

    public int update(User pojo){
        return userMapper.update(pojo);
    }

    /**
     * 如果结果为空，list是null还是空集合?
     * 结论：空集合
     * @param sex
     * @return
     */
    public List<User> find(Sex sex){
        return userMapper.findBySex(sex);
    }

    /**
     * 查不到，Long是null还是默认值0
     * 结论：null
     * @param username
     * @return
     */
    public Long find(String username){
        return userMapper.findByUsername(username);
    }

    /**
     * count，Integer是null还是默认值0
     * 结论：null
     * @param username
     * @return
     */
    public Integer count(String username){
        return userMapper.count(username);
    }


    /**
     * 如何参数是null，sql语句是否会报错？
     * 结论：不会报错，返回null
     * @param id
     * @return
     */
    public User findById(Long id){
        return userMapper.findById(id);
    }
}
